﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for _Account
/// </summary>
public class _Account
{
	public _Account()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public int _id_account_number { get; set; }
    public int _id_company_bank { get; set; }
    public string _account_number { get; set; }

    static SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);

    public static _Account Select(string company_bank_id)
    {
        _Account account = new _Account();
        SqlCommand SelCmd = new SqlCommand("SELECT * FROM account_number WHERE id_company_bank=@company_bank_id", conn);
        SelCmd.Parameters.Add(new SqlParameter("@company_bank_id", System.Data.SqlDbType.Int)).Value = company_bank_id;
        conn.Open();
        SqlDataReader dr = SelCmd.ExecuteReader();
        while (dr.Read())
        {
            account._id_account_number = (int) dr[0];
            account._id_company_bank = (int) dr[2];
            account._account_number = dr[1].ToString();
        }
        dr.Close();
        conn.Close();
        return account;
    }

    public static _Account SelectByDocumentAccountID(string document_account_id)
    {
        _Account account = new _Account();
        SqlCommand SelCmd = new SqlCommand("SELECT * FROM account_number WHERE ID_account_number=@ID_account_number", conn);
        SelCmd.Parameters.Add(new SqlParameter("@ID_account_number", System.Data.SqlDbType.Int)).Value = document_account_id;
        conn.Open();
        SqlDataReader dr = SelCmd.ExecuteReader();
        while (dr.Read())
        {
            account._id_account_number = (int)dr[0];
            account._id_company_bank = (int)dr[2];
            account._account_number = dr[1].ToString();
        }
        dr.Close();
        conn.Close();
        return account;
    }
}